package com.cloudlibrary.mapper;

import com.cloudlibrary.domain.Book;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;


/**
* @author 33582
* @description 针对表【book】的数据库操作Mapper
* @createDate 2024-12-12 15:29:10
* @Entity com.cloudlibrary.domain.Book
*/
@Mapper
public interface BookMapper {
    @Select("select * from book where book_status != '3' order by book_uploadtime desc")
    @Results(id = "bookMap",value ={
            @Result(id = true,column = "book_id",property = "id"),
            @Result(column = "book_name",property = "name"),
            @Result(column = "book_isbn",property = "isbn"),
            @Result(column = "book_press",property = "press"),
            @Result(column = "book_author",property = "author"),
            @Result(column = "book_pagination",property = "pagination"),
            @Result(column = "book_price",property = "price"),
            @Result(column = "book_uploadtime",property = "uploadTime"),
            @Result(column = "book_status",property = "status"),
            @Result(column = "book_borrower",property = "borrower"),
            @Result(column = "book_borrowtime",property = "borrowTime"),
            @Result(column = "book_returntime",property = "returnTime"),
    })
    Page<Book> selectNewBooks();

    @Select("select * from book where book_id = #{id}")
    @Results(id = "findByIdMap",value ={
            @Result(id = true,column = "book_id",property = "id"),
            @Result(column = "book_name",property = "name"),
            @Result(column = "book_isbn",property = "isbn"),
            @Result(column = "book_press",property = "press"),
            @Result(column = "book_author",property = "author"),
            @Result(column = "book_pagination",property = "pagination"),
            @Result(column = "book_price",property = "price"),
            @Result(column = "book_uploadtime",property = "uploadTime"),
            @Result(column = "book_status",property = "status"),
            @Result(column = "book_borrower",property = "borrower"),
            @Result(column = "book_borrowtime",property = "borrowTime"),
            @Result(column = "book_returntime",property = "returnTime"),
    })
    Book findById(String id);
    @Update({"<script>",
            "update book",
            "  <set>",
            "    <if test='name != null'>book_name=#{name},</if>",
            "    <if test='isbn != null'>book_isbn=#{isbn},</if>",
            "    <if test='press != null'>book_press=#{press},</if>",
            "    <if test='author != null'>book_author=#{author},</if>",
            "    <if test='pagination != null'>book_pagination=#{pagination},</if>",
            "    <if test='price != null'>book_price=#{price},</if>",
            "    <if test='uploadTime != null'>book_uploadtime=#{uploadTime},</if>",
            "    <if test='status != null'>book_status=#{status},</if>",
            "    <if test='borrower != null'>book_borrower=#{borrower},</if>",
            "    <if test='borrowTime != null'>book_borrowtime=#{borrowTime},</if>",
            "    <if test='returnTime != null'>book_returntime=#{returnTime},</if>",
            "  </set>",
            "where book_id=#{id}",
            "</script>"})
    @Results(id = "editBook",value ={
            @Result(id = true,column = "book_id",property = "id"),
            @Result(column = "book_name",property = "name"),
            @Result(column = "book_isbn",property = "isbn"),
            @Result(column = "book_press",property = "press"),
            @Result(column = "book_author",property = "author"),
            @Result(column = "book_pagination",property = "pagination"),
            @Result(column = "book_price",property = "price"),
            @Result(column = "book_uploadtime",property = "uploadTime"),
            @Result(column = "book_status",property = "status"),
            @Result(column = "book_borrower",property = "borrower"),
            @Result(column = "book_borrowtime",property = "borrowTime"),
            @Result(column = "book_returntime",property = "returnTime"),
    })
    Integer editBook(Book book);
}




